package com.lzh.healthCode.business.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lzh.healthCode.business.entity.CjInfoBean;
import com.lzh.healthCode.business.entity.JgInfoBean;
import com.lzh.healthCode.business.service.CjInfoService;
import com.lzh.healthCode.business.service.JgInfoService;
import com.lzh.healthCode.business.service.ZyInfoService;
import com.lzh.healthCode.core.BaseConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Controller
@RequestMapping("Error")
@Slf4j
public class ErrorShow extends BaseConfig {

    @Resource
    CjInfoService cjInfoService;

    @Resource
    ZyInfoService zyInfoService;

    @Resource
    JgInfoService jgInfoService;


//    public void sampleReport(UpdAreaEnum updAreaEnum, UpdTypeEnum updTypeEnum) {
//        // 测试人员信息上传接口 【参数】
//        UpdParams updParams = new UpdParams(updAreaEnum, updTypeEnum);
//        List<CjInfoBean> selectAll = cjInfoService.getSelectTime(updParams);
//        for (CjInfoBean cjInfoBean : selectAll) {
//            commonService.uploadSampleReport(updAreaEnum, updTypeEnum, cjInfoBean);
//        }
//
//    }
//
//
//    public void transportReport(UpdAreaEnum updAreaEnum, UpdTypeEnum updTypeEnum) {
//        // 测试人员信息上传接口 【参数】
//        UpdParams updParams = new UpdParams(updAreaEnum, updTypeEnum);
//        List<ZyInfoBean> selectAll = zyInfoService.getSelectTime(updParams);
//        for (ZyInfoBean zyInfoBean : selectAll) {
//            commonService.uploadtransportReport(updAreaEnum, updTypeEnum, zyInfoBean);
//        }
//
//    }
//
//
//    public void checkResultReport1(UpdAreaEnum updAreaEnum, UpdTypeEnum updTypeEnum) {
//        // 测试人员信息上传接口 【参数】
//        UpdParams updParams = new UpdParams(updAreaEnum, updTypeEnum);
//        List<JgInfoBean> selectAll = jgInfoService.getSelectTime(updParams);
//        for (JgInfoBean jgInfoBean : selectAll) {
//            commonService.uploadcheckResultReport(updAreaEnum, updTypeEnum, jgInfoBean);
//        }
//
//    }
@GetMapping("ShowError")
public String errorShowsampleReport(Model model)  {
    //
    List<CjInfoBean> selectAll = cjInfoService.getSelecError();
    model.addAttribute("selectAll",selectAll);
    return  "ShowError";
}
@GetMapping("/ShowErrorBySampleno")
    public String getSelectSupp(@RequestParam String SAMPLENO, Model model)  {
        //
        List<CjInfoBean> selectAll = cjInfoService.getSelectSupp(SAMPLENO);
        model.addAttribute("selectAll",selectAll);
        return  "updateShowError";
    }

    @PostMapping("/update")
    public String update(@RequestParam String SAMPLENO,String BJCRZJHM ,String BJCRSJH){
       cjInfoService.update(SAMPLENO,BJCRZJHM ,BJCRSJH);
        return "redirect:/Error/ShowError";
    }
    @GetMapping("errorcheckResultReport")
    public JSONArray errorcheckResultReport() {
        //查询失败信息接口
        List<JgInfoBean> selectAll = jgInfoService.getSelecError();
        JSONArray jsonArray = new JSONArray();
        for (JgInfoBean jgInfoBean : selectAll) {
            JSONObject jsonObject = new JSONObject();
//            jsonObject.put("bjcrxm", cjInfoBean.getBJCRXM());
            jsonObject.put("reason_jg", jgInfoBean.getREASON_JG());
            jsonArray.add(jsonObject);
//            System.out.println("编码：" + jsonArray);
        }

        return jsonArray;
    }


}